﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace 委托事件验证控件
{
    public partial class ValidationTextbox : UserControl
    {
        public ValidationDelegate onValidation;

        public ValidationTextbox()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (onValidation != null)
            {
                ValidationEventArgs args = new ValidationEventArgs();
                args.Value = textBox1.Text;
                args.IsValid = true;
                onValidation(args);
                if (args.IsValid == false)
                {
                    MessageBox.Show("数据错误");
                }
            }
        }
    }

    public delegate void ValidationDelegate(ValidationEventArgs e);

    public class ValidationEventArgs
    {
        public bool IsValid { get; set; }
        public string Value { get; set; }
    }
}
